package com.schoolcloud.common.model;

public class R<T> {
    private Integer code;
    private String msg;
    private T data;

    private R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public R() {};
    private R(REnum r, T data) {
        this.code = r.getCode();
        this.msg = r.getMsg();
        this.data = data;
    }
    private R(REnum r) {
        this.code = r.getCode();
        this.msg = r.getMsg();
    }
    public static <T> R<T> ok() {
        return new R<>(REnum.OK);
    }


    public static <T> R<T> ok(T data) {
        return new R<>(REnum.OK, data);
    }

    public static <T> R<T> ok(String msg, T data) {
        return new R<>(200, msg, data);
    }

    public static R<Object> err() {
        return new R<>(403, "操作失败", null);
    }
    public static R<Object> err(REnum rEnum) {
        return new R<>(rEnum);
    }
    public static R<Object> err(String msg) {
        return new R<>(403, msg, null);
    }

    public static R<Object> err(Integer code, String msg) {
        return new R<>(code, msg, null);
    }

    public static R<Object> err(Object data) {
        return new R<>(403, "操作失败", data);
    }

    public static R<Object> err(Integer code, String msg, Object data) {
        return new R<>(code, msg, data);
    }

    public T getData() {
        return data;
    }

    public R<?> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public R<?> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public R<?> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

}
